﻿Public Class Search
    Dim columnIndex As Integer
    Dim columnName As String

    Private Sub Search_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim loc As Point
        loc = Control.MousePosition
        Me.Location = loc
        Me.TextBox1.Focus()
        columnIndex = DataGridViewForm.PartsDataGridView.SortedColumn.Index
        columnName = DataGridViewForm.PartsDataGridView.Columns(columnIndex).HeaderText.ToString
        Label1.Text = columnName
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Try
            DataGridViewForm.PartsBindingSource.Filter = String.Format("{0} = '{1}'", DataGridViewForm.ShopPartsDataSet.Parts.Columns(columnIndex).ColumnName.ToString, TextBox1.Text)
        Catch
            MessageBox.Show("Database error")
        End Try
        Me.Close()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class